package com.enation.app.shop.front.policyInsurance.appController;

import com.enation.app.base.core.model.Member;
import com.enation.app.base.core.service.IMemberManager;
import com.enation.app.shop.front.policyInsurance.entity.RbtDispersion;
import com.enation.app.shop.front.policyInsurance.service.DispersionMapper;
import com.enation.framework.action.JsonResult;
import com.enation.framework.util.JsonResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Scope("prototype")
@Controller
@RequestMapping("/web/govermentManage")
public class InPolicyGovermentController {
    @Autowired
    private DispersionMapper dispersionMapper;
    @Autowired
    private IMemberManager memberManager;

    /**
     * 获得所有散户
     * @param userid
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllDispersion")
    public JsonResult getAllDispersion(Integer userid){
        try {
            List list=new ArrayList();
            Member member= memberManager.getapp(userid);
            List<RbtDispersion> dispersions=dispersionMapper.getAllDispersion();
            for(RbtDispersion rbtDispersion:dispersions){
                boolean flag=member.getProvince_id()==rbtDispersion.getDisProvinceId()
                        &&member.getCity_id()==rbtDispersion.getDisCityId()
                        &&member.getRegion_id()==rbtDispersion.getDisRegionId();
                if(flag){
                    list.add(rbtDispersion);
                }
            }
            return JsonResultUtil.getObjectMessageJson(list,"获取散户列表成功!");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResultUtil.getErrorJson("获取失败!");
        }
    }

    @ResponseBody
    @RequestMapping("/getAllOrderInfo")
    public JsonResult getAllOrderInfo(){

        return null;
    }


}
